﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using PMS.BLL;
using PMS.Entity;
using PMS;
using PMS.Resources;
using PMS.Win;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraGrid.Views.Grid.ViewInfo;
using DevExpress.XtraGrid.Views.Base;
using PMS.Utils;
using System.Collections;
namespace PMS.ChucNang
{
    public partial class ThongBaoThuocHetHan : FormManualBase
    {
        private ChiTietPhieuNhapBO m_Service;

        public ChiTietPhieuNhapBO service 
        {
            get 
            {
                if (m_Service == null)
                {
                    m_Service = new ChiTietPhieuNhapBO();
                }
                return m_Service;
            }
            set { m_Service = value; }
        }

        public ThongBaoThuocHetHan(string FunctionID) 
            :base(FunctionID)
        {
            InitializeComponent();

            grvDetailList.OptionsBehavior.Editable = false;
            grvDetailList.OptionsView.ShowGroupPanel = false;
            grvDetailList.OptionsView.ShowIndicator = true;

            grvDetailList.OptionsView.ShowAutoFilterRow = true;
            grvDetailList.OptionsView.ShowFilterPanelMode = ShowFilterPanelMode.Never;
            grvDetailList.OptionsView.ShowGroupedColumns = false;
            grvDetailList.OptionsMenu.EnableColumnMenu = false;
            grvDetailList.OptionsCustomization.AllowColumnMoving = false;
            grvDetailList.OptionsCustomization.AllowGroup = false;
            grvDetailList.OptionsFilter.AllowFilterEditor = false;

            this.grvDetailList.OptionsSelection.MultiSelect = false;
            this.grvDetailList.IndicatorWidth = Constants.INDICATOR_WIDTH;
            //gridbinding
            this.colMaThuoc.FieldName = LuuKhoColumns.MaThuoc.ToString();
            this.colHoatChat.FieldName = SanPhamColumns.TenHoatChat.ToString();
            this.colBietDuoc.FieldName = SanPhamColumns.TenBietDuoc.ToString();
            this.colNongDo.FieldName = SanPhamColumns.NongDoHamLuong.ToString();
            this.colDonVi.FieldName = DonViTinhColumns.TenDonVi.ToString();
            this.colSoLo.FieldName = LuuKhoColumns.SoLo.ToString();
            this.colTonKho.FieldName = LuuKhoColumns.TonKho.ToString();
            this.colNgaySanXuat.FieldName = LuuKhoColumns.NgaySX.ToString();
            this.colHanSD.FieldName = LuuKhoColumns.HanSuDung.ToString();
            this.colHanDung.FieldName = LuuKhoColumns.HanDung.ToString();

            txtSoThang.Properties.Mask.EditMask = ConfigurationConstant.PositiveNumericFormatString;
            txtSoThang.Properties.Mask.MaskType = DevExpress.XtraEditors.Mask.MaskType.Numeric;
            txtSoThang.Properties.Mask.UseMaskAsDisplayFormat = true;
            

            txtColTonKho.Mask.EditMask = ConfigurationConstant.PositiveNumericFormatString;
            txtColTonKho.Mask.MaskType = DevExpress.XtraEditors.Mask.MaskType.Numeric;
            txtColTonKho.Mask.UseMaskAsDisplayFormat = true;

            
        }

        private void btnProcess_Click(object sender, EventArgs e)
        {
            try
            {
                int sothang = DataConvertUltils.ToInt(txtSoThang.EditValue);
                DateTime tungay = DateTime.Now.AddMonths(sothang);

                int songay = (tungay - DateTime.Now).Days;

                grdDetailList.DataSource = service.GetAllThuocHetHangTrongThoiGian(songay);
            }
            catch (Exception ex)
            {
                ShowErrorMessage(ex);
            }

        }

        private void grvDetailList_CustomDrawRowIndicator(object sender, RowIndicatorCustomDrawEventArgs e)
        {
            if ((e.Info.IsRowIndicator) && (e.RowHandle >= 0))
            {
                e.Info.DisplayText = (e.RowHandle + 1).ToString();
            }
        }


    }
}